﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Test1
{
    class GenericList<T>
    {
        private Node<T> head;
        private Node<T> tail;
        public GenericList()
        {
            head = tail = null;
        }
        public Node<T> Head
        {
            get => head;
        }
        public void add(T t)
        {
            Node<T> node = new Node<T>(t);
            if (tail == null)
            {
                head = tail = node;
            }
            else
            {
                tail.next = node;
                tail = node;
            }
        }
        public static void ForEach(GenericList<T> genericList, Action<T> action)
        {
            if (genericList == null)
            {
                Console.WriteLine("链表为空");
                return;
            }
            Node<T> node = genericList.Head;
            while (node.next != null)
            {
                action(node.data);
                node = node.next;
            }
        }
    }
}
